package com.zhenwei.dao;

import com.zhenwei.domain.Customer;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CustomerDao {

    @Select("select *from cst_customer")
    @Results({@Result(column="cust_id", property="custId"),
            @Result(column="cust_name", property="custName"),
            @Result(column="cust_industry", property="custIndustry"),
            @Result(column="cust_address", property="custAddress"),
            @Result(column="cust_phone", property="custPhone"),
            @Result(column="cust_level", property="custLevel"),
            @Result(column="cust_source", property="custSource")})
    public List<Customer> findAll();

    @Select("select *from cst_customer where cust_Id=#{custId} ")
    @Results({@Result(id =true, column="cust_id", property="custId"),
            @Result(column="cust_name", property="custName"),
            @Result(column="cust_industry", property="custIndustry"),
            @Result(column="cust_address", property="custAddress"),
            @Result(column="cust_phone", property="custPhone"),
            @Result(column="cust_level", property="custLevel"),
            @Result(column="cust_source", property="custSource")})
    Customer findById(String custId);

    @Update("update cst_customer set " +
            "cust_name=#{custName}," +
            "cust_industry=#{custIndustry}," +
            "cust_address=#{custAddress}," +
            "cust_phone=#{custPhone}," +
            "cust_level=#{custLevel}," +
            "cust_source=#{custSource} where " +
            "cust_id=#{custId}")
    void update(Customer customer);

}
